package cn.itcast.shop.categorysecond.dao;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.sun.org.apache.bcel.internal.generic.ISTORE;

import cn.itcast.shop.categorysecond.vo.CategorySecond;
import cn.itcast.shop.utils.PageHibernateCallback;
/**
 * 二级分类    持久 层
 * @author Administrator
 *
 */
public class CategorySecondDao extends HibernateDaoSupport {
	
	//DAO层 二级分类的个数
	public int findCount() {
		int totalCount = 0 ;
		String hql = "select count(*) from CategorySecond ";
		List<Long> list = this.getHibernateTemplate().find(hql) ;
		if(list != null & list.size() >0){
			totalCount = list.get(0).intValue();
		}
		return totalCount;
	}
	
	//DAO层 当前页二级分类的数据集合
	public List<CategorySecond> findByPage(int begin, int limit) {
		
		String hql = "from CategorySecond cs order by csid desc ";
		List<CategorySecond> list = null ;
		list = this.getHibernateTemplate().execute(new PageHibernateCallback<CategorySecond>(hql, null, begin, limit));
		if(list != null && list.size()>0){
			return list ;
		}
		return null;
	}
	//DAO层  保存添加的数据！
	public void save(CategorySecond categorySecond) {
		this.getHibernateTemplate().save(categorySecond);
	}
	//DAO层  查询该实体！
	public CategorySecond findByCsid(Integer csid) {
		return this.getHibernateTemplate().get(CategorySecond.class, csid);
	}
	//DAO层 删除实体！
	public void delete(CategorySecond categorySecond) {
		this.getHibernateTemplate().delete(categorySecond);
	}
	//DAO层  更新实体
	public void update(CategorySecond categorySecond) {
		this.getHibernateTemplate().update(categorySecond);
	}
	
	//DAO层  后台查询所有
	public List<CategorySecond> findAll() {
		String hql = "from CategorySecond cs order by cs.csid " ;
		List<CategorySecond> list = this.getHibernateTemplate().find(hql);
		if(list != null && list.size() > 0){
			return list ;
		}
		return null;
	}

	
}
